<template>

	<view class="content">
		<cu-custom bgColor="bg-white" :isBack="true" textRight="true" type="custom-recuit">
			<block slot="backText" class="titilestyle">{{title}}</block>

		</cu-custom>

		<!--  订单搜索的开始 -->
		<view class="search-boxes" :style="[{minHeight:StatusBar.height+5+'px'}]">
			<view class="search-boxes-item" :style="[{minHeight:StatusBar.height+5+'px'}]">
				<view class="input-search-box1 ">
					<input class="inputSearch1" type="text" value="" v-model="param.keywords"
						placeholder="输入您想查找的岗位关键词" />

					<text class="cuIcon-roundclosefill text-gray" style="font-size: 45rpx;"
						v-if="param.keywords.length>5" @click="clearKeyword"></text>
					<text class="cuIcon-search iconsousuo" @click="search"></text>
				</view>
			</view>

		</view>
		<!--  订单搜索的结束 -->
		<view class="itemBox" v-if="param.keywords.length==0">
			<view class="basis-xll flex justify-between">
				<text class="padding-tb text-blod">历史搜索</text>
				<text class="padding-tb cuIcon-delete" @click="clear"></text>
			</view>
			<view class="basis-xll flex flex-wrap">
				<view class='cu-tag radius tag-style padding-sm margin-xs' v-for="(tag,i) in history" v-if="i<20"
					@click="searchTag(tag)">{{tag}}</view>
			</view>

		</view>
		<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption"
			:up="upOption">

			<PostList :postData='postData'></PostList>

		</mescroll-body>
	</view>
</template>

<script>
	import PostList from "../../components/postList.vue"
	import MescrollBody from "@/uni_modules/mescroll-uni/components/mescroll-body/mescroll-body.vue"
	export default {
		components: {

			MescrollBody,
			PostList

		},
		data() {
			return {
				title: "搜索岗位",
				StatusBar: this.Custom,
				history: [],
				postData: [],
				mescroll: null,
				downOption: {
					use: false, // 是否启用下拉刷新; 默认true
					native: false,
					auto: false, // 是否在初始化完毕之后自动执行下拉刷新的回调; 默认true
				},
				upOption: {
					use: true, // 是否启用上拉加载; 默认true
					auto: false, // 是否在初始化完毕之后自动执行上拉加载的回调; 默认true
					page: {
						num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
						size: 10 // 每页数据的数量,默认10
					},
					load: false,
					onScroll: true,
					noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					empty: {
						tip: '暂无相关数据',
						tips: ""
					},
					textNoMore: '到底啦'
				},
				param: {
					area_id: uni.getStorageSync('area_id'),
					page: 0,
					limit: 10,
					type: "",
					school: "",
					keywords: "",
					city: ""

				}

			}
		},
		watch: {
			keywords(val) {

			}
		},
		onLoad() {
			let history = uni.getStorageSync("offer_history");
			(history) ? (() => {
				this.history = history.reverse();
			})() : "";
		},
		onPullDownRefresh() {
			this.downCallback();
		},
		onReachBottom() {
			this.upCallback(this.mescroll);
		},
		methods: {
			searchTag(tag) {
				this.param.keywords = tag;
				this.mescroll.resetUpScroll();
			},

			search() {
				if (this.param.keywords.length == 0) {
					uni.showToast({
						title: "请输入要查询的岗位",
						icon: "none"
					})
					return false;
				}
				(this.history.indexOf(this.param.keywords) == -1) ? (() => {
					this.mescroll.resetUpScroll();
					this.history.unshift(this.param.keywords);
					uni.setStorageSync("offer_history", this.history);
				})() : "";

			},
			clearKeyword() {
				console.log("清空")
				this.param.keywords = "";
			},
			clear() {
				this.history = [];
				uni.removeStorage({
					key: "offer_history",
					success: () => {

					}
				})
			},
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			downCallback() {

				this.upCallback(this.mescroll);


			},
			upCallback(page) {
				if (!page.num) {
					return false;
				}
				console.log(page);
				this.param.page = page.num;
				this.param.limit = page.size;

				this.apiRequest('/buyer/OfferList', this.param, "get", 0).then(res => {
					console.log(res);
					uni.stopPullDownRefresh();
					if (res.code != 200) {
						this.mescroll.endSuccess()
					}
					if (page.num == 1) {
						this.postData = []
					}

					this.postData = this.postData.concat(res.data.data); //追加新数据
					console.log(this.postData)
					this.mescroll.endBySize(this.postData.length, res.data.total);

				}).catch(() => {
					uni.stopPullDownRefresh()
					this.mescroll.endErr();
				})


			},


		}


	}
</script>

<style scoped>
	/**
	 * 搜索框样式
	 */
	.search-boxes {
		width: 100vw;
		display: flex;
		position: relative;
		background: #F7F7F7;
		margin: 0 0 20rpx 0;

	}

	.search-boxes-item {
		position: fixed;
		z-index: 999;
		display: flex;
		width: 100vw;
		padding: 20rpx 0;
		background: #F7F7F7;

	}

	.itemBox {
		width: 92%;
		margin: auto;
	}

	.input-search-box1 {
		width: 92%;
		flex-direction: row;
		margin-left: 4%;
		display: flex;
		align-items: center;
		position: relative;
		align-items: center;
		padding: 20upx 30upx 20upx 30upx;
		box-shadow: 0px 0px 20upx 0px rgba(0, 0, 0, 0.05);
		border-radius: 20upx;
		background-color: white;

	}

	.inputSearch1 {
		width: 80%;
	}
</style>
